export default {
    props:{
        row:{
            type:Object,
            default:function () {
                return {}
            }
        },
        disabled:{
            type:Boolean,
            default:true
        }
    },
    data() {
        return {
            formData: {},
        }
    },
    created() {
        for(let o in this.row){
            if(this.row[o]!=undefined){
                this.formData[o] = this.row[o]
            }
        }
    },
    methods: {
        close() {
            this.$emit('update:visible', false)
        },
        closeAndReload(res) {
            this.$emit("reloadList")
            this.msgSuccess(res.msg)
            this.close()
        },
        toAdd() {
            this.$refs['elForm'].validate(valid => {
                if (!valid) return
                this.addForm(this.formData)
            })
        },
        addForm(data){
          let url = this.$route.fullPath.split("?")
            const api = require(`@/api/${this.apiUrl?this.apiUrl:url[0].replace("/", "")
            }/index`);
            if (data.id) {
                api.default.toEdit(data.id, data).then(res => {
                    this.$emit("reloadList")
                    this.msgSuccess(res.msg)
                    this.close()
                })
            } else {
                api.default.toAdd(data).then(res => {
                    this.$emit("reloadList")
                    this.msgSuccess(res.msg)
                    this.close()
                })
            }
        }
    }
}
